﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;


namespace BeatingMole
{
    class CInfoEnemy
    {
        string _tenchuot, _spritesheet, _hinhtrangthai; 
        int _mau, _tocdo, _diem, _sttcathinh, _sohinhcat;
        //public bool _iscolliding;
        Rectangle _boundingbox;
        Vector2 _vitri;
        Vector2 _origin;
        State _trangthai;        
        Texture2D _textture;
        Dictionary<string, Rectangle> _spritexml;
        ContentManager _content;
        GameTime _gameTime;
        SpriteBatch _spriteBatch;

        #region "Property"
        /// <summary>
        /// Tên Enemy
        /// </summary>
        public string Ten 
        {
            get {return _tenchuot;}
            set{_tenchuot=value;}
        }
        /// <summary>
        /// Spritesheet
        /// </summary>
        public string SpriteSheet 
        {
            get {return _spritesheet;}
            set{_spritesheet=value;}
        }
        /// <summary>
        /// Tên hình trạng thái VD: stand_
        /// </summary>
        public string HinhTrangThai 
        {
            get {return _hinhtrangthai;}
            set{_hinhtrangthai=value;}
        }
        /// <summary>
        /// Lượng máu của Enemy
        /// </summary>
        public int Mau 
        {
            get { return _mau; }
            set { _mau = value; }
        }
        /// <summary>
        /// Tốc độ xuất hiện của Enemy
        /// </summary>
        public int TocDo 
        {
            get { return _tocdo; }
            set { _tocdo = value; }
        }
        /// <summary>
        /// Điểm của mỗi Enemy
        /// </summary>
        public int DiemSo 
        {
            get { return _diem; }
            set { _diem = value; }
        }
        /// <summary>
        /// Số hình cắt của trạng thái.
        /// </summary>
        public int SoHinhCat
        {
            get { return _sohinhcat; }
            set { _sohinhcat = value; }
        }
        /// <summary>
        /// Số thứ tự hình cắt
        /// </summary>
        public int STTCatHinh
        {
            get { return _sttcathinh; }
            set { _sttcathinh = value; }
        }
        /// <summary>
        /// Vùng bao của Mỗi Enemy
        /// </summary>
        public Rectangle BoundingBox 
        {
            get { return _boundingbox; }
            set { _boundingbox = value; }
        }
        /// <summary>
        /// Vị trí của Enemy
        /// </summary>
        public Vector2 ViTri 
        {
            get { return _vitri; }
            set { _vitri = value; }
        }
        /// <summary>
        /// Toạ độ chân của Enemy
        /// </summary>
        public Vector2 Origin
        {
            get { return _origin; }
            set { _origin = value; }
        }
        /// <summary>
        /// Trạng thái của mỗi Enemy
        /// </summary>
        public State TrangThai 
        {
            get { return _trangthai; }
            set { _trangthai = value; }
        }
        /// <summary>
        /// Textture
        /// </summary>
        public Texture2D Texture
        {
            get { return _textture; }
            set { _textture = value; }
        }
        
        //public bool IsColliding
        //{
        //    get { return _iscolliding; }
        //    set { _iscolliding = value; }
        //}

        public ContentManager Content
        {
            get { return _content; }
            set { _content = value; }
        }

        public GameTime GameTime
        {
            get { return _gameTime; }
            set { _gameTime = value; }
        }

        public SpriteBatch SpriteBatch
        {
            get { return _spriteBatch; }
            set { _spriteBatch = value; }
        }
        /// <summary>
        /// Xml Sprisheet
        /// </summary>
        public Dictionary<String, Rectangle> ImageEnemy
        {
            get { return _spritexml; }
            set { _spritexml = value; }
        }
        #endregion

        #region [Constructor]
        public CInfoEnemy() { }

        /// <summary>
        /// Khởi tạo tất cả tham số
        /// </summary>
        /// <param Ten="Ten">Tên Enemy</param>
        /// <param Ten="spritesheet">Spritesheet</param>
        /// <param Ten="HinhTrangThai">Tên hình trạng thái</param>
        /// <param Ten="Mau">Máu</param>
        /// <param Ten="TocDo">Tốc độ</param>
        /// <param Ten="DiemSo">Điểm</param>
        /// <param Ten="rectangle">Vùng bao Rectangle Enemy</param>
        /// <param Ten="ViTri">Vị trí vẽ Enemy</param>
        /// <param Ten="TrangThai">Trạng thái của Enemy</param>
        public CInfoEnemy(string Ten, string spritesheet, string HinhTrangThai,
            int Mau, int TocDo, int DiemSo, Rectangle boundngbox, Vector2 ViTri, Vector2 Origin, State TrangThai)
        {
            _tenchuot = Ten;
            _spritesheet = spritesheet;
            _hinhtrangthai = HinhTrangThai;
            _mau = Mau;
            _tocdo = TocDo;
            _diem = DiemSo;
            _boundingbox = boundngbox;
            _vitri = ViTri;
            _origin = Origin;
            _trangthai = TrangThai;
        }
        /// <summary>
        /// Khởi tạo tham số CInfoEnemy
        /// </summary>
        /// <param Ten="a">Đối tượng Enemy</param>
        public CInfoEnemy(CInfoEnemy a)
        {
            _tenchuot = a._tenchuot;
            _spritesheet = a._spritesheet;
            _hinhtrangthai = a._hinhtrangthai;
            _mau = a._mau;
            _tocdo = a._tocdo;
            _diem = a._diem;
            _boundingbox = a._boundingbox;
            _vitri = a._vitri;
            _origin = a._origin;
            _trangthai = a._trangthai;
        }

        public CInfoEnemy(ContentManager content, SpriteBatch spitebatch, GameTime gametime)
        {
            _content = content;
            _spriteBatch = spitebatch;
            _gameTime = gametime;
            LoadContent();

            _tenchuot = "Mole 1";
            _mau = 100;
            _tocdo = 120;
            _diem = 20;
            _vitri = new Vector2(100, 100);
            _hinhtrangthai = "mole_d";
            _sohinhcat = 6;
            _trangthai = State.Visible;
        }

        #endregion

        //Load Content
        public void LoadContent()
        {
            if (_content != null)
            {
                _textture = _content.Load<Texture2D>("Resource/spritesheet");               
                _spritexml = _content.Load<Dictionary<string, Rectangle>>("Resource/spritesheetxml");
            }
        }


        /// <summary>
        /// Kiểm tra trạng thái Enemy
        /// </summary>
        public void TrangThaiEnemy()
        {
            if (this.TrangThai == State.Visible)
            {
                this.SoHinhCat = 3;
                this.HinhTrangThai = "mole_d";
                this.STTCatHinh = 0;
            }
            else if (this.TrangThai == State.Die)
            {
                this.SoHinhCat = 1;
                this.HinhTrangThai = "die_";
                this.STTCatHinh = 0;
            }
        }
      
    }
}
